
var e = getApp(), a = e.requirejs("core"), t = e.requirejs("wxParse/wxParse"), i = e.requirejs("biz/diypage"), s = e.requirejs("jquery");

Page({
  /**
   * 页面的初始数据
   */
  data: {
    selector: 0,
    // 左侧菜单
    leftMenuList:[],
    // 右侧菜单
    rightContent:[],
    topic:[],
    isFocus:false,
    inpValue:"",
   // 参数
    cid:'',
    keywords:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // console.log(options)
    if(options.id==''){
      this.getCates (this.data.cid)
    }else{
      this.getCates (options.id)
      this.setData({
        selector:options.id
      })
    }
    // this.getleftMenuList()
    this.getCates (this.data.cid)
  },

  onShow:function(){
    let id=wx.getStorageSync('cid')
   let cid=id
   this.setData({
     cid
   })
   this.getCates (this.data.cid)
  }
  ,

 // 获取分类数据
  getCates (id) {
    if(id==1){
      id='rec'
    }
  a.get('sns/board&cid='+id+'&keywords=',{id},(res) => {
    // console.log(res)
    const leftMenuList = res.result.category
    let rightContent =  res.result.list
    this.setData({
      rightContent,
      leftMenuList
    })
  })
},

  // 获取搜索数据
  qsearch(query){
    a.get('sns/board&cid=&keywords='+query,{query},(res) => {
      // console.log(res)
      let topic = res.result.list
      this.setData({
        topic
      })
    })
  },
  // 左侧菜单的点击事件
  tabCategory (e) {
    // console.log(e)
    const {id} = e.currentTarget.dataset
    // console.log(id)
    
    this.setData({
      selector:id,
      cid:id,
    })
    // console.log(this.data.cid)
    this.getCates(this.data.cid)
  },

// 搜索
  bindInput(e){
    // console.log(e)
    const {value}=e.detail
    // console.log(value)
    this.setData({
      keywords:value,
      isFocus:true
    })
    this.qsearch(this.data.keywords)
  },
  // 删除事件
  handleCancel(){
    this.setData({
      inpValue:'',
      topic:[],
      isFocus:false
    })
  },
  
// 获取板块id
// getidHadle(e){
//   console.log(e);
  
//   // this.bid=this.QueryParams.id
//   //  wx.setStorageSync('id', this.bid)
// }
})